home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / doc / homepage / tutorials / lesson5 / musical.wrl < prev    next >
Text File  |  1996-08-21  |  1KB  |  52 lines

  1. #VRML V2.0 utf8
  2. #Example of the use and control of sound
  3.  
  4. #Sphere which will act as an on/off switch
  5. DEF SPHERE Transform {
  6.   translation 0 0 0 
  7.   children [
  8.     DEF CLICKER TouchSensor {} 
  9.     Shape {
  10.       appearance Appearance {
  11.          material Material {diffuseColor 0 0 1}   
  12.       }
  13.       geometry Sphere {radius 3}
  14.     }
  15.   ]
  16. }
  17.  
  18. #Script to control the music
  19. DEF MUSIC_SCRIPT Script {
  20.   url "musical.class"
  21.   scriptType "javabc"
  22.  
  23.   field SFNode sphere_trans USE SPHERE
  24.  
  25.   eventOut SFTime musicOn   
  26.   eventOut SFTime musicOff
  27.   eventIn SFBool clicked
  28. }
  29.  
  30. #sound node
  31. DEF MUSICALSOUND Sound  {
  32.   #inner radius - intensity is max within this 
  33.   minBack  20
  34.   minFront 20   
  35.   #outer radius - sound drops off between inner 
  36.   #radius and this, and can't be heard beyond this 
  37.   maxBack  50
  38.   maxFront 50   
  39.   intensity 1
  40.   source DEF MUSICALCLIP AudioClip {
  41.     url "musical.wav"
  42.     loop TRUE
  43.     stopTime 1
  44.   }
  45. }
  46.  
  47. #route for mouse click
  48. ROUTE CLICKER.isActive TO MUSIC_SCRIPT.clicked
  49. #routes for music control
  50. ROUTE MUSIC_SCRIPT.musicOn TO MUSICALCLIP.set_startTime 
  51. ROUTE MUSIC_SCRIPT.musicOff TO MUSICALCLIP.set_stopTime 
  52.